home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 with MFC / Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso / CODE / Chap09 / Paint5 / MainFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-05  |  2.3 KB  |  86 lines

  1. //***********************************************************************
  2. //
  3. //  MainFrame.cpp
  4. //
  5. //***********************************************************************
  6.  
  7. #define OEMRESOURCE
  8.  
  9. #include <afxwin.h>
  10. #include <afxext.h>
  11. #include "Resource.h"
  12. #include "CLine.h"
  13. #include "MainFrame.h"
  14. #include "Paint5Doc.h"
  15.  
  16. IMPLEMENT_DYNCREATE (CMainFrame, CFrameWnd)
  17.  
  18. BEGIN_MESSAGE_MAP (CMainFrame, CFrameWnd)
  19.     ON_WM_CREATE ()
  20.     ON_WM_MEASUREITEM ()
  21.     ON_WM_DRAWITEM ()
  22. END_MESSAGE_MAP ()
  23.  
  24. int CMainFrame::OnCreate (LPCREATESTRUCT lpcs)
  25. {
  26.     if (CFrameWnd::OnCreate (lpcs) == -1)
  27.         return -1;
  28.  
  29.     CMenu* pMenu = GetMenu ();
  30.     for (int i=0; i<8; i++)
  31.         pMenu->ModifyMenu (ID_COLOR_BLACK + i,
  32.             MF_BYCOMMAND | MF_OWNERDRAW, ID_COLOR_BLACK + i);
  33.     return 0;
  34. }
  35.  
  36. BOOL CMainFrame::OnCreateClient (LPCREATESTRUCT lpcs,
  37.     CCreateContext* pContext)
  38. {
  39.     return m_wndSplitter.Create (this, 2, 2, CSize (1, 1), pContext);
  40. }
  41.  
  42. void CMainFrame::OnMeasureItem (int nIDCtl, LPMEASUREITEMSTRUCT lpmis)
  43. {
  44.     lpmis->itemWidth = ::GetSystemMetrics (SM_CYMENU) * 4;
  45.     lpmis->itemHeight = ::GetSystemMetrics (SM_CYMENU);
  46. }
  47.  
  48. void CMainFrame::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpdis)
  49. {
  50.     BITMAP bm;
  51.     CBitmap bitmap;
  52.     bitmap.LoadOEMBitmap (OBM_CHECK);
  53.     bitmap.GetObject (sizeof (bm), &bm);
  54.  
  55.     CDC dc;
  56.     dc.Attach (lpdis->hDC);
  57.  
  58.     CBrush* pBrush = new CBrush (::GetSysColor ((lpdis->itemState &
  59.         ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU));
  60.     dc.FrameRect (&(lpdis->rcItem), pBrush);
  61.     delete pBrush;
  62.  
  63.     if (lpdis->itemState & ODS_CHECKED) {
  64.         CDC dcMem;
  65.         dcMem.CreateCompatibleDC (&dc);
  66.         CBitmap* pOldBitmap = dcMem.SelectObject (&bitmap);
  67.  
  68.         dc.BitBlt (lpdis->rcItem.left + 4, lpdis->rcItem.top +
  69.             (((lpdis->rcItem.bottom - lpdis->rcItem.top) -
  70.             bm.bmHeight) / 2), bm.bmWidth, bm.bmHeight, &dcMem,
  71.             0, 0, SRCCOPY);
  72.  
  73.         dcMem.SelectObject (pOldBitmap);
  74.     }
  75.  
  76.     pBrush = new CBrush (CPaintDoc::m_crColors[lpdis->itemID -
  77.         ID_COLOR_BLACK]);
  78.     CRect rect = lpdis->rcItem;
  79.     rect.DeflateRect (6, 4);
  80.     rect.left += bm.bmWidth;
  81.     dc.FillRect (rect, pBrush);
  82.     delete pBrush;
  83.  
  84.     dc.Detach ();
  85. }
  86.